package observable.emitter

import observable.ObservableProxy
import observer.Observer

/**
 * 发射器工厂类
 */
object EmitterFactory {
    fun <T> create(observer: Observer<T>, observable: ObservableProxy<T>): Emitter<T> {
        return object : Emitter<T> {
            override fun onNext(obj: T) {
                observable.dispatchObserve {
                    observer.onNext(obj)
                }
            }

            override fun onError(throwable: Throwable) {
                observable.dispatchObserve {
                    observer.onError(throwable)
                }
            }

            override fun onComplete() {
                observable.dispatchObserve {
                    observer.onComplete()
                }
            }
        }
    }
}